package college;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

//로그인 창
public class login extends JFrame {
	private static login framess;
	private JPanel contentPane;
	private JTextField id;
	private JPasswordField pw;

	/**
	 * Launch the application.11
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					login frame = new login();
					frame.setLocationRelativeTo(null);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	public login() {
		// 창 제목
		setTitle("로그인 창 입니다");
		// 창 크기
		setBounds(400, 250, 450, 300);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		contentPane = new JPanel();
		setContentPane(contentPane);
		
		contentPane.setLayout(new BorderLayout(0, 0));
		// 상단 패널 생성
		JPanel top = new JPanel();
		top.setPreferredSize(new Dimension(10, 100));
		contentPane.add(top, BorderLayout.NORTH);
		top.setLayout(new BorderLayout(0, 0));
		// 로그인 레이블 패널 생성
		JPanel log = new JPanel();
		top.add(log, BorderLayout.SOUTH);
		// 로그인 레이블 생성
		JLabel login = new JLabel("로그인");
		login.setFont(new Font("돋움", Font.BOLD, 18));
		log.add(login);
		// 확인 버튼 패널 생성
		JPanel downp = new JPanel();
		downp.setBorder(new EmptyBorder(7, 7, 7, 7));
		contentPane.add(downp, BorderLayout.SOUTH);
		// 오른쪽 정렬
		downp.setLayout(new BorderLayout(0, 0));
		
		JPanel ok = new JPanel();
		downp.add(ok, BorderLayout.EAST);
		// 조건문
		JButton okb = new JButton("확인");
		okb.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int result = JOptionPane.showConfirmDialog(null, "로그인하시겠습니까", "로그인창입니다", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
				if( result == JOptionPane.YES_OPTION)
					// 맞다면 CollegeMain으로 넘어감
					new CollegeMain(framess);
				else if( result == JOptionPane.NO_OPTION)
					// 틀리다면 종료
					System.exit(0);
			}
		});
		ok.add(okb);
		// 가운데 패널 생성
		JPanel center = new JPanel();
		contentPane.add(center, BorderLayout.CENTER);
		GridBagLayout gbl_center = new GridBagLayout();
		// 로그인 메세지 상하좌우 간격
		gbl_center.columnWidths = new int[]{0, 0, 0, 120, 0};
		gbl_center.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0};
		gbl_center.rowHeights = new int[]{10, 0, 20, 5, 2, 0};
		gbl_center.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		center.setLayout(gbl_center);
		// 아이디 라벨 생성
		JLabel idl = new JLabel("아이디");
		idl.setFont(new Font("돋움", Font.BOLD, 16));
		GridBagConstraints gbc_idl = new GridBagConstraints();
		gbc_idl.anchor = GridBagConstraints.WEST;
		gbc_idl.gridx = 1;
		gbc_idl.gridy = 2;
		center.add(idl, gbc_idl);
		// 아이디 입력 텍스트필드
		id = new JTextField();
		GridBagConstraints gbc_id = new GridBagConstraints();
		// 왼쪽 정렬
		gbc_id.fill = GridBagConstraints.HORIZONTAL;
		gbc_id.insets = new Insets(0, 0, 5, 5);
		gbc_id.gridx = 3;
		gbc_id.gridy = 2;
		center.add(id, gbc_id);
		
		// 비밀번호 라벨
		JLabel pwl = new JLabel("비밀번호");
		pwl.setFont(new Font("돋움", Font.BOLD, 16));
		GridBagConstraints gbc_pwl = new GridBagConstraints();
		gbc_pwl.insets = new Insets(0, 0, 5, 5);
		gbc_pwl.gridx = 1;
		gbc_pwl.gridy = 3;
		center.add(pwl, gbc_pwl);
		// 비밀번호 입력 텍스트필드
		pw = new JPasswordField();
		GridBagConstraints gbc_pw = new GridBagConstraints();
		gbc_pw.insets = new Insets(0, 0, 5, 5);
		gbc_pw.fill = GridBagConstraints.HORIZONTAL;
		gbc_pw.gridx = 3;
		gbc_pw.gridy = 3;
		center.add(pw, gbc_pw);
	}

}
